package com.example.ui.activity;

import android.os.Bundle;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SpinnerIconActivity extends AppCompatActivity {

    private static final int[] iconArr = {
            R.drawable.qqq, R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,
            R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,
            R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,
            R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,
            R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,
            R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,R.drawable.qqq,
     };
    private static final String[] iconStrArr = {
            "qqq","qqq","qqq","qqq",
            "qqq","qqq","qqq","qqq",
            "qqq","qqq","qqq","qqq",
            "qqq","qqq","qqq","qqq",
            "qqq","qqq","qqq","qqq",
            "qqq","qqq","qqq","qqq",
    };

    private Spinner sp_dropdown;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_spinner_icon);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        sp_dropdown = findViewById(R.id.sp_dropdown);
        // 声明一个映射对象的列表，用来封装图标和文本
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < iconArr.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("icon", iconArr[i]);
            map.put("text", iconStrArr[i]);
            list.add(map);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,list,R.layout.item_simple,
                new String[]{"icon","text"},
                new int[]{R.id.iv_icon,R.id.tv_text}
                );
        sp_dropdown.setAdapter(simpleAdapter);
        sp_dropdown.setSelection(0);
    }
}